package thelib

import (
	"time"
	"math/rand"
)

/*生成[start,end]之间的随机数*/
func CreateRandomInt(start int, end int) int {
	<-time.After(1 * time.Nanosecond)
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	n := start + r.Intn(900)
	return n
}

/*测试一个数是否是偶数*/
func IsEven(n int) bool {
	return n%2 == 0
}

/*统计管道中奇偶数的个数*/
/*func CountOddEven(ch <-chan int) (retMap map[string]int) {
	retMap = make(map[string]int)
	retMap["奇数"] = 0
	retMap["偶数"] = 0

	for n := range ch {
		if IsEven(n) {
			retMap["偶数"] ++
		} else {
			retMap["奇数"] ++
		}
	}
	return
}*/

/*测试一个数是否水仙花数*/
func IsNarcissistic(n int) bool {
	a := n / 100
	b := n % 100 / 10
	c := n % 10
	return (a*a*a + b*b*b + c*c*c) == n
}
